/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ClassesJava;

import connexion.ConnectionManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 *
 * @author Administrateur
 */
public class Cours {
     private int idcour;
	private int dure;
	private String description;
         private String date;
         public ConnectionManager c;
	Cours(int idcour,int dure,String description, String date) {
		this.idcour =idcour;
		this.dure=dure;
                 this.description=description;
                 this.date=date;
	
}
	public int getIdcour() {
		return idcour;
	}
	public void setIdcour(int idcour) {
		this.idcour = idcour;
	}
	public int getDure() {
		return dure;
	}
	public void setDure(int dure) {
		this.dure = dure;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
         public String getDate() {
		return date;
	}
	public void setDate(String date) {
		this.date = date;
	}
	public int ajoutersCour(Cours r) {
           int i;
        c = new ConnectionManager();
        String rq = "INSERT INTO  `gestion_des_emplois`.`lecours` (idCours ,dure,description,date)"
                + " VALUES (NULL ,'" + r.getDure() + "', '" + r.getDescription()+ "','" +getDate() + "')";
        i = c.setDataBase(rq);
        return i;
        }
	public int modifierCour(Cours r){
             int i = 0;
        c = new ConnectionManager();
        String rq = "UPDATE  `gestion_des_emplois`.`lecours` SET `dure` = '" + r.getDure() + "', "
                + "`description` = '" + r.getDescription() + "'date'='"+r.getDate()+"' where idCours=" + r.getIdcour();
        i = c.setDataBase(rq);
        return i;
        }
	public int supprimerCour(Cours r){
         int i = 0;
        c = new ConnectionManager();
        String rq = "DELETE FROM `gestion_des_emplois`.`lecours` where idCours=" + r.getIdcour();
        i = c.setDataBase(rq);
        return i;
        }
	   public Vector<Cours> getCours() {
         Vector<Cours> res = new Vector();
        try {
            c = new ConnectionManager();
            ResultSet rs = c.getDataBase("select * from lecours");

            while (rs.next()) {
               Cours r = new Cours( rs.getInt(1),rs.getInt(2),rs.getString(3), rs.getString(4));
                res.add(r);
            }

        } catch (SQLException ex) {
            Logger.getLogger(Salle.class.getName()).log(Level.SEVERE, null, ex);
        }

        return res;
        }
    
}

